package com.csoa.community.activity;

import android.content.Intent;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.collect.community.R;
import com.csoa.community.utils.StringUtils;

public class VideoActivity extends BaseProcessPhotoActivity {
	private LinearLayout layoutCameraYF;
	StringBuffer sbImgUrl = new StringBuffer("");
	private String mImgUrl = "";
	private EditText etTitleCamera;
	private EditText etAuthorCamera;
	private String title = "";
	private String author = "";
	private String mImgName = "";

	@Override
	public void initUI() {
		setContentView(R.layout.camera_info);
		mWhich = 1;
		mImgUrl = this.getIntent().getStringExtra("imgPath");
		mImgName = this.getIntent().getStringExtra("imgName");
		title = this.getIntent().getStringExtra("title");
		author = this.getIntent().getStringExtra("author");
		sbImgUrl.append(mImgUrl);

		etTitleCamera = (EditText) this.findViewById(R.id.etTitleCamera);
		etTitleCamera.setText(title);
		etAuthorCamera = (EditText) this.findViewById(R.id.etAuthorCamera);
		etAuthorCamera.setText(author);
		layoutCameraYF = (LinearLayout) this.findViewById(R.id.layoutCameraYF);
		Button btnCamera = (Button) this.findViewById(R.id.btnCamera);
		btnCamera.setText("录像");
		btnCamera.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
				startActivityForResult(intent, 1);
			}
		});
		this.findViewById(R.id.btnImport).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
						intent.setType("video/*");
						startActivityForResult(intent, 1);
					}
				});

		this.findViewById(R.id.btnSave).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						String imgName = getImgName(false);
						String imgPath = getImgPath(false);
						title = etTitleCamera.getText().toString();
						author = etAuthorCamera.getText().toString();
						Intent intent = new Intent();
						intent.putExtra("imgPath", imgPath);
						intent.putExtra("imgName", imgName);
						intent.putExtra("title", title);
						intent.putExtra("author", author);
						setResult(RESULT_OK, intent);
						finish();
					}
				});

		this.findViewById(R.id.btnCancel).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						finish();
					}
				});
		this.findViewById(R.id.btnBack).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						finish();
					}
				});

	}

	@Override
	public void initData() {
		if (!StringUtils.isEmpty(mImgUrl)) {
			fillBitmapToLayout(mImgUrl, mImgName, layoutCameraYF, false);
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK) {
			this.isCamera = false;
			String path = this.showImg(layoutCameraYF, data);
			// if (!StringUtils.isEmpty(path)) {
			// if (StringUtils.isEmpty(sbImgUrl.toString())) {
			// sbImgUrl.append(path);
			// } else {
			// sbImgUrl.append("," + path);
			// }
			// }

		}
	}

}
